package com.lego.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpSession;

@WebFilter("/*")
public class Filter01 extends HttpFilter implements Filter {
       protected void doFilter(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, FilterChain chain) throws IOException ,ServletException {
    	   HttpSession session = request.getSession();
    	   Object u = session.getAttribute("loginUser");
    	   String url = request.getRequestURI();
    	   System.out.println(url);
    	   if(u!=null||url.endsWith("login.jsp")||url.endsWith("adminLogin.do")||
    			   url.endsWith("index.jsp")||url.endsWith("login.do")||
    			   url.endsWith("register.do")||url.endsWith(".css")||
    			   url.endsWith(".js")||url.endsWith(".jpg")||
    			   url.endsWith(".png")||url.endsWith(".jpeg")||
    			   url.endsWith("purchase.jsp")||
    			   url.endsWith("selectGoods.do")||url.endsWith("selectGoods.jsp")||
    			   url.endsWith("admin.jsp")||url.endsWith("changeStaById.do")||
    			   url.endsWith("purchase.do")||url.endsWith("lego/")||
    			   url.endsWith("1.avif")|| url.endsWith("adminLogin.do")||
    			   url.endsWith("selectConment")||url.endsWith("admin.css")||
    			   url.endsWith("selectOverview.do")||url.endsWith("querySellers.do")||
    			   url.endsWith("modifySeller.do")||url.endsWith("checkSellerName.do")||
    			   url.endsWith("queryUsers.do")||url.endsWith("deleteUserInfo.do")||
    			   url.endsWith("delConmentServlet")||url.endsWith("updateGoodsQuantity.do")||
    			   url.endsWith("updateGoods.do")||url.endsWith("selectUserOrders.do")||
    			   url.endsWith("changeStaById.do")||url.endsWith("changeStaById.do")||
    			   url.endsWith("chart.umd.min.js")||url.endsWith("addSeller.do")||
    			   url.endsWith("adminLogin.jsp")||url.endsWith("selectOrderByONum.do")||
    			   url.endsWith("addGoods.do")||url.endsWith("admLogout.do")) {
    		   chain.doFilter(request, response);
    	   }else {
    		   response.sendRedirect("/lego/login.jsp");
    	   }
       };
}
